

let oform=document.forms[0]
let username=oform.username.value;
let pwd=oform.pwd.value;
let headerimg=oform.headerimg.value;


//不为空按钮红色
// let btn=oform.btn;
// console.log(btn);
// let ochild=oform.querySelectorAll('input')
// for(let i=0;i<ochild.length;i++){
//   ochild[i].addEventListener('blur',function(){
   
//     if((username!='')&&(pwd!='')){
      
//       let btn=oform.btn;
//       btn.style.opacity='1';
//     }
      
//   })
  
// }

oform.addEventListener('submit',function(e){
    var e=e||window.Event
    
   
   let username=oform.username.value;
   let pwd=oform.pwd.value;
   let headerimg=oform.headerimg.value;

 
   
  if((username!='')&&(pwd!='')){
    
   let btn=oform.btn;
   btn.style.opacity=1;
    let obj={
      id:Date.now(),
      username:username,
      pwd:pwd,
      headerimg:headerimg
  }
  console.log(obj);
   getSign(obj)
  }else{
    alert('账号,密码为必填项!')
  }
  e.preventDefault()
})


function getSign(user){
   
       axios.post('http://api.yuguoxy.com/api/member/add', {
        username: user.username,
        password: user.pwd,
       
      })
      .then(function (response) {
        
        let data=response.data
        console.log(data);
        let{resultCode} = data
       
        if(resultCode==1){ 
                alert('注册成功!')
                location.href='../pages/login.html'
        }else{
          alert('该用户已注册！')
        }
       
      })
      .catch(function (error) {
        console.log(error);
      });
}
